<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Translation</title>
        <style type="text/css">
            body {
                font-family: Arial;
            }
            .table1 {
                width: 1150px;
            }
            .table1 th {
                text-align: left;
                font-size: 12px;
            }
            .table1 td {
                vertical-align: top;
                font-size: 12px;
                text-align: left;
                font-weight: bold;
            }
            .table1 td textarea{
                width: 580px;
                height: 60px;
                font-family: Arial;
                font-size: 12px;
            }
            .nav_bar {
                font-family: Arial;
                font-size: 14px;
                font-weight: bold;
                text-align: left;
                padding-left: 50px;
                margin-top: 10px;
            }
            .nav_bar a {
                text-decoration: none;
                color: black;
            }
            .gr_ty_st{
                padding-top: 10px; 
                padding-left: 5px; 
                color: red; 
                font-style: italic;
                font-weight: bold;
            }
            /*            #filter_by_div {
                            position: absolute; 
                            width: 345px;
                            margin-top: 20px;
                        } */
            #filter_by_div input[type='text']{
                width: 310px;
            }
            #clr_flt {
                background-image: url('images/clear_filter.png');
                position: absolute;
                z-index: 5;
                width: 13px;
                height: 13px;
                margin-top: 5px;
                left: 360px;
                background-repeat: no-repeat;
                cursor: pointer;
            }
            #filtered_levels_div {
                color: grey;
                margin-top: 4px;
            }
        </style>
        <!--[if IE]>
        <style>
/*            #filter_by_div {
                position: absolute; 
                width: 345px;
                top: 80px;
                left: 45px;
            } */
        </style>
        <![endif]-->
        <link rel="stylesheet" href="tinyeditor/tinyeditor.css">
        <script src="tinyeditor/tiny.editor.js"></script>
    </head>
    <body>
        <?php
//        var_dump($_REQUEST);
        //Please specify the database access here
        require_once 'includes/php/connect_db.php';
        $flt_pages = array();
        $flt_vars = array();
        $where = "(1) ";
        if ( $_REQUEST['filter_by_text'] != '' ) {
            $sql = "
            SELECT str_k_var_number, lng_fk_page_list
            FROM tbl_0953_text_translations    
            WHERE
            ";
            if ( $_REQUEST['filter_by_radio'] == 'filter_by_varname' ) {
                $where = "
                str_k_var_name LIKE '%{$_REQUEST['filter_by_text']}%'
                ";
            } else {
                if ( $_REQUEST['filter_level'] == 'filter_l_13' ) {
                    $where = "
                    (      str_new_english_checked LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_new_german_checked LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_old_english LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_old_german LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_new_english_draft LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_new_german_draft LIKE '%{$_REQUEST['filter_by_text']}%'
                     )
                    ";
                } else {
                    $where = "
                    (      str_new_english_checked LIKE '%{$_REQUEST['filter_by_text']}%'
                        OR str_new_german_checked LIKE '%{$_REQUEST['filter_by_text']}%'
                     )
                    ";
                }
            }
            if ( !$res = mysql_query($sql . $where) ) {
                die("Error in line " . __LINE__ . ":<br>" . mysql_error());
            }
            while ( $row = mysql_fetch_assoc($res) ) {
//                    echo "<pre>".var_dump($row)."</pre>";
                if ( !in_array($row['lng_fk_page_list'], $flt_pages) ) {
                    $flt_pages[] = $row['lng_fk_page_list'];
                }
                if ( !in_array($row['str_k_var_number'], $flt_vars) ) {
                    $flt_vars[] = $row['str_k_var_number'];
                }
            }
        }
        $flt_pages = implode(",", $flt_pages);
        $flt_vars = implode(",", $flt_vars);
        $sql = "
        SELECT * 
        FROM tbl_0950_page_list
        WHERE (1)
        " . ($_REQUEST['filter_by_text'] != '' ? "AND lng_k_page_list IN (" . ($flt_pages ? $flt_pages : "-1") . ")" : "") . "
        ORDER BY page_name
        ";
//        echo $sql;
        if ( !$res = mysql_query($sql) ) {
            die("Error in line " . __LINE__ . ":<br>" . mysql_error());
        }
        while ( $row = mysql_fetch_assoc($res) ) {
            $page_list[] = array('id' => $row['lng_k_page_list'], 'name' => $row['page_name'], 'prefix' => $row['str_var_prefix'], 'edit_mode' => $row['i_type']);
            $page_prefixes[$row['lng_k_page_list']] = $row['str_var_prefix'];
        }
//        echo count($page_list) . "|" . $_REQUEST['page_name']."<br>";
        if ( /* $_REQUEST['filter_by_text'] != '' && */ count($page_list) > 0 && ($_REQUEST['page_name'] == '-1' || $_REQUEST['page_name'] == '') ) {
            $_REQUEST['page_name'] = $page_list[0]['id'];
        }
//        echo count($page_list) . "|" . $_REQUEST['page_name'];
        $sql = "SELECT * FROM tbl_0952_text_group ORDER BY str_group_name";
        if ( !$res = mysql_query($sql) ) {
            die("Error in line " . __LINE__ . ":<br>" . mysql_error());
        }
        while ( $row = mysql_fetch_assoc($res) ) {
            $text_group_list[] = array('id' => $row['lng_k_text_group'], 'name' => $row['str_group_name'], 'description' => $row['str_description']);
        }
        $sql = "SELECT * FROM tbl_0951_text_type ORDER BY st_text_type";
        if ( !$res = mysql_query($sql) ) {
            die("Error in line " . __LINE__ . ":<br>" . mysql_error());
        }
        while ( $row = mysql_fetch_assoc($res) ) {
            $text_type_list[] = array('id' => $row['lng_k_text_type'], 'type' => $row['st_text_type'], 'description' => $row['str_description']);
        }
        $sql = "SELECT * FROM tbl_0956_text_status  ORDER BY str_text_status";
        if ( !$res = mysql_query($sql) ) {
            die("Error in line " . __LINE__ . ":<br>" . mysql_error());
        }
        while ( $row = mysql_fetch_assoc($res) ) {
            $status_list[] = array('id' => $row['lng_k_text_status'], 'status' => $row['str_text_status'], 'description' => $row['str_description']);
        }
        if ( $_REQUEST['text_group'] != '' && $_REQUEST['text_group'] != '-1' ) {
            $filter .= " AND lng_fk_text_group = '{$_REQUEST['text_group']}'";
        }
        if ( $_REQUEST['text_type'] != '' && $_REQUEST['text_type'] != '-1' ) {
            $filter .= " AND lng_fk_text_type = '{$_REQUEST['text_type']}'";
        }
        if ( $_REQUEST['text_status'] != '' && $_REQUEST['text_status'] != '-1' ) {
            if ( $_REQUEST['text_status2'] == '1' || $_REQUEST['text_status2'] == '2' ) {
                $filter .= " AND (lng_fk_text_status_en = '{$_REQUEST['text_status']}' " . ($_REQUEST['text_status2'] == '1' ? "OR" : "AND") . " lng_fk_text_status_ge = '{$_REQUEST['text_status']}')";
            } else {
                if ( $_REQUEST['text_status2'] == '3' ) {
                    $filter .= " AND lng_fk_text_status_en = '{$_REQUEST['text_status']}'";
                } else {
                    $filter .= " AND lng_fk_text_status_ge = '{$_REQUEST['text_status']}'";
                }
            }
        }
        if ( $flt_vars != "" ) {
            $filter .= " AND str_k_var_number IN ($flt_vars)";
        }
        $sql = "SELECT * FROM tbl_0953_text_translations WHERE $where " . $filter;
        if ( !$res = mysql_query($sql) ) {
            die("Error in line " . __LINE__ . ":<br>" . mysql_error() . "<br/>" . $sql);
        }
        while ( $row = mysql_fetch_assoc($res) ) {
            $variable_list[$row['lng_fk_page_list']][] = array('id' => $row['str_k_var_number'], 'name' => $row['str_k_var_name']);
        }
        foreach ( $_REQUEST as $key => $value ) {
            $_REQUEST[$key] = mysql_real_escape_string($value);
        }
        $filtered_l_1_color = $filtered_l_2_color = $filtered_l_3_color = "";
        if ( $_REQUEST['action'] != "" && $_REQUEST['page_name'] != '-1' && $_REQUEST['variable_name'] != '-1' ) {
            if ( $_REQUEST['action'] == 'load' ) {
                $sql = "SELECT * FROM tbl_0953_text_translations 
                    WHERE 
                    $where                    
                    AND i_record_status = 0
                    {$filter}
                    AND lng_fk_page_list = '{$_REQUEST['page_name']}'
                    AND str_k_var_number = '{$_REQUEST['variable_name']}'
                    ORDER BY str_k_var_name";
                if ( !$res = mysql_query($sql) ) {
                    die("Error in line " . __LINE__ . ":<br>" . mysql_error() . "<br>" . $sql);
                }
                $data = mysql_fetch_assoc($res);
                foreach ( $data as $key => $value ) {
                    $data[$key] = mysql_real_escape_string($value);
                }
                $selected_items['page_list'] = $data['lng_fk_page_list'];
                $selected_items['variable_list'] = $data['str_k_var_number'];
                if ( $_REQUEST['filter_by_text'] != '' && $_REQUEST['filter_by_radio'] != 'filter_by_var_name' ) {
                    if ( stripos($data['str_new_english_checked'], $_REQUEST['filter_by_text']) !== false || stripos($data['str_new_german_checked'], $_REQUEST['filter_by_text']) !== false ) {
                        $filtered_l_3_color = "color: red;";
                    }
                    if ( stripos($data['str_new_english_draft'], $_REQUEST['filter_by_text']) !== false || stripos($data['str_new_german_draft'], $_REQUEST['filter_by_text']) !== false ) {
                        $filtered_l_2_color = "color: red;";
                    }
                    if ( stripos($data['str_old_english'], $_REQUEST['filter_by_text']) !== false || stripos($data['str_old_german'], $_REQUEST['filter_by_text']) !== false ) {
                        $filtered_l_1_color = "color: red;";
                    }
                }
//                echo "<pre>"; var_dump($data); echo "</pre>";
            } else if ( $_REQUEST['action'] == 'save' ) {
                $_REQUEST['english_old'] = utf8_decode($_REQUEST['english_old']);
                $_REQUEST['eng_link'] = utf8_decode($_REQUEST['eng_link']);
                $_REQUEST['eng_comments'] = utf8_decode($_REQUEST['eng_comments']);
                $_REQUEST['eng_draft_editor'] = utf8_decode($_REQUEST['eng_draft_editor']);
                $_REQUEST['eng_check_editor'] = $_REQUEST['eng_check_editor'];

                $_REQUEST['german_old'] = utf8_decode($_REQUEST['german_old']);
                $_REQUEST['ger_link'] = utf8_decode($_REQUEST['ger_link']);
                $_REQUEST['ger_comments'] = utf8_decode($_REQUEST['ger_comments']);
                $_REQUEST['ger_draft_editor'] = utf8_decode($_REQUEST['ger_draft_editor']);
                $_REQUEST['ger_check_editor'] = $_REQUEST['ger_check_editor'];
                
                $sql = "
                UPDATE tbl_0953_text_translations SET
                    lng_fk_text_status_en = '" . ($_REQUEST['en_status'] != "" ? $_REQUEST['en_status'] : "1") . "',
                    str_new_english_link = '{$_REQUEST['eng_link']}',
                    str_english_comments = '{$_REQUEST['eng_comments']}',
                    str_new_english_draft = '{$_REQUEST['eng_draft_editor']}',
                    str_new_english_checked = '{$_REQUEST['eng_check_editor']}',
                    lng_fk_text_status_ge = '" . ($_REQUEST['ge_status'] != "" ? $_REQUEST['ge_status'] : "1") . "',
                    str_new_german_link = '{$_REQUEST['ger_link']}',
                    str_german_comments = '{$_REQUEST['ger_comments']}',
                    str_new_german_draft = '{$_REQUEST['ger_draft_editor']}',
                    str_new_german_checked = '{$_REQUEST['ger_check_editor']}',
                    i_save_timestamp = '".  time()."'
                WHERE str_k_var_number = '{$_REQUEST['variable_name']}'
                AND lng_fk_page_list = '{$_REQUEST['page_name']}'
                ";
                if ( !$res = mysql_query($sql) ) {
                    die("Error in line " . __LINE__ . ":<br>" . mysql_error());
                }
                $sql = "SELECT * FROM tbl_0953_text_translations 
                    WHERE i_record_status = 0
                    AND lng_fk_page_list = '{$_REQUEST['page_name']}'
                    AND str_k_var_number = '{$_REQUEST['variable_name']}'";
                if ( !$res = mysql_query($sql) ) {
                    die("Error in line " . __LINE__ . ":<br>" . mysql_error());
                }
                $data = mysql_fetch_assoc($res);
                foreach ( $data as $key => $value ) {
                    $data[$key] = mysql_real_escape_string($value);
                }
                $selected_items['page_list'] = $data['lng_fk_page_list'];
                $selected_items['variable_list'] = $data['str_k_var_number'];
            } elseif ( $_REQUEST['action'] == 'reassign' ) {
                $sql = "
                UPDATE tbl_0953_text_translations SET
                    lng_fk_text_group = '{$_REQUEST['text_group_2']}',
                    lng_fk_text_type = '{$_REQUEST['text_type_2']}'
                WHERE str_k_var_number = '{$_REQUEST['variable_name']}'
                AND lng_fk_page_list = '{$_REQUEST['page_name']}'
                ";
                if ( !$res = mysql_query($sql) ) {
                    die("Error in line " . __LINE__ . ":<br>" . mysql_error());
                }
                $sql = "SELECT * FROM tbl_0953_text_translations 
                    WHERE i_record_status = 0
                    AND lng_fk_page_list = '{$_REQUEST['page_name']}'
                    AND str_k_var_number = '{$_REQUEST['variable_name']}'";
                if ( !$res = mysql_query($sql) ) {
                    die("Error in line " . __LINE__ . ":<br>" . mysql_error());
                }
                $data = mysql_fetch_assoc($res);
                foreach ( $data as $key => $value ) {
                    $data[$key] = str_replace("'", "&apos;", $value);
                    $data[$key] = str_replace('"', "&quot;", $value);
                }
                $selected_items['page_list'] = $data['lng_fk_page_list'];
                $selected_items['variable_list'] = $data['str_k_var_number'];
            }
        } else {
            $selected_items['page_list'] = '-1';
            $selected_items['variable_list'] = '-1';
            $selected_items['load_first'] = true;
        }
        foreach ( $text_group_list as $key => $value ) {
            if ( $value['id'] == $data['lng_fk_text_group'] ) {
                $group = $value['name'];
            }
        }
        foreach ( $text_type_list as $key => $value ) {
            if ( $value['id'] == $data['lng_fk_text_type'] ) {
                $type = $value['type'];
            }
        }
        foreach ( $status_list as $key => $value ) {
            if ( $value['id'] == $data['lng_fk_text_status_en'] ) {
                $status_en = $value['status'];
            }
            if ( $value['id'] == $data['lng_fk_text_status_ge'] ) {
                $status_ge = $value['status'];
            }
        }
        ?>
        <script type="text/javascript">
            var page_list = <?= json_encode($page_list) ?>;
            var text_group_list = <?= json_encode($text_group_list) ?>;
            var text_type_list = <?= json_encode($text_type_list) ?>;
            var status_list = <?= json_encode($status_list) ?>;
            var variable_list = <?= json_encode($variable_list) ?>;
            var selected_items = <?= json_encode($selected_items) ?>;
            var eng_check_editor;
            page_list.findById = function (id){
                for (var i = 0; i < this.length; i++){
                    if (typeof this[i] != 'function'){
                        if (this[i].id == id){
                            return this[i];
                        }
                    }
                }
                return false;
            }
            function getObj(id){
                return document.getElementById(id);
            }
            function addElement(tgt_select, option_text, option_value)	{
                var oOption = document.createElement("option");
                oOption.value = option_value;
                oOption.appendChild(document.createTextNode(option_text));
                tgt_select.appendChild(oOption);
            }
            
            function clearCombobox(tgt_select){
                for (var i = 0; i <= tgt_select.length; i++) {
                    tgt_select.remove(1);
                }
            }
            
            function fill_comboboxes(){
                var cbxPageList = getObj('page_name');
                var cbxTextGroup = getObj('text_group');
                var cbxTextGroup2 = getObj('text_group_2');
                var cbxTextType = getObj('text_type');
                var cbxTextType2 = getObj('text_type_2');
                var cbxTextStatus = getObj('text_status');
                var cbxTextStatus2 = getObj('text_status2');
                var cbxVariableList = getObj('variable_name');
                if (page_list != null){
                    for (var i = 0; i < page_list.length; i++) {
                        addElement(cbxPageList, page_list[i].name, page_list[i].id);
                    }
                }
                for (var i = 0; i < text_group_list.length; i++) {
                    addElement(cbxTextGroup, text_group_list[i].name, text_group_list[i].id);
                    addElement(cbxTextGroup2, text_group_list[i].name, text_group_list[i].id);
                }
                for (var i = 0; i < text_type_list.length; i++) {
                    addElement(cbxTextType, text_type_list[i].type, text_type_list[i].id);
                    addElement(cbxTextType2, text_type_list[i].type, text_type_list[i].id);
                }
                for (var i = 0; i < status_list.length; i++) {
                    addElement(cbxTextStatus, status_list[i].status, status_list[i].id);
                }
                cbxPageList.value = '<?= ($_REQUEST['page_name'] != "" ? $_REQUEST['page_name'] : "-1") ?>';
                if (cbxPageList.selectedIndex == '-1'){
                    if (cbxPageList.length > 1){
                        cbxPageList.selectedIndex = 1;
                    } else {
                        cbxPageList.value = '-1';
                        selected_items.variable_list = '-1';
                    }
                }
                fill_variable_list(cbxPageList.value);
                if (cbxVariableList.selectedIndex == 0 && cbxVariableList.length > 1 && (selected_items.variable_list == '-1' || selected_items.variable_list == undefined || selected_items.variable_list == 'null')){
                    cbxVariableList.selectedIndex = 1;
                    cbxTextGroup.value = '<?= ($_REQUEST['text_group'] != "" ? $_REQUEST['text_group'] : "-1") ?>';
                    cbxTextType.value = '<?= ($_REQUEST['text_type'] != "" ? $_REQUEST['text_type'] : "-1") ?>';
                    cbxTextStatus.value = '<?= ($_REQUEST['text_status'] != "" ? $_REQUEST['text_status'] : "-1") ?>';
                    cbxTextStatus2.value = '<?= ($_REQUEST['text_status2'] != "" ? $_REQUEST['text_status2'] : "1") ?>';
                    load_data('load');
                } else {
                    cbxVariableList.value = selected_items.variable_list;
                }
                cbxTextGroup.value = '<?= ($_REQUEST['text_group'] != "" ? $_REQUEST['text_group'] : "-1") ?>';
                cbxTextType.value = '<?= ($_REQUEST['text_type'] != "" ? $_REQUEST['text_type'] : "-1") ?>';
                cbxTextStatus.value = '<?= ($_REQUEST['text_status'] != "" ? $_REQUEST['text_status'] : "-1") ?>';
                cbxTextStatus2.value = '<?= ($_REQUEST['text_status2'] != "" ? $_REQUEST['text_status2'] : "1") ?>';
            }
            
            function fill_variable_list(page){
                var cbxVariableList = getObj('variable_name');
                clearCombobox(cbxVariableList);
                if (variable_list && variable_list[page]){
                    for (var i = 0; i < variable_list[page].length; i++) {
                        addElement(cbxVariableList, variable_list[page][i].name, variable_list[page][i].id);
                    }
                }
            }
            
            function copy_old(obj){
                if (obj.id == 'eng_copy'){
                    eng_draft_editor.setContent(getObj('english_old').value);
                }
                if (obj.id == 'ger_copy'){
                    ger_draft_editor.setContent(getObj('german_old').value);
                }
            }
            function copy_new(obj){
                if (obj.id == 'eng_copy_new'){
                    eng_check_editor.setContent(eng_draft_editor.getContent());
                }
                if (obj.id == 'ger_copy_new'){
                    ger_check_editor.setContent(ger_draft_editor.getContent());
                }
            }
            function finishing(lang){
                if (eval(lang + "_to_check_editor").getContent() != ''){
                    if (confirm('The text in "to be checked" field will be overwritten.\nContinue?')){
                        var s_lang = (lang == "english"?"eng":"ger");
                        copy_new({id: s_lang + '_copy_new'});
                    }
                } else {
                    var s_lang = (lang == "english"?"eng":"ger");
                    copy_new({id: s_lang + '_copy_new'});
                }
            }
            function load_data(row){
                if (row == undefined){
                    alert('Unknown action.');
                } else if(row == 'save'){
                    getObj('action').value = row;
                    eng_draft_editor.post();
                    ger_draft_editor.post();
                    if (page_list.findById(selected_items.page_list).edit_mode != 2){
                        eng_check_editor.post();
                        ger_check_editor.post();
                    }
                } else {
                    getObj('action').value = row;
                }
                getObj('frmMain').submit();
            }
            function clear_form(){
                if (confirm("All editable fields will be cleared.\nContinue?")){
                    getObj('eng_comments').value = "";
                    getObj('eng_link').value = "";
                    getObj('ger_comments').value = "";
                    getObj('ger_link').value = "";
                    eng_draft_editor.setContent('');
                    eng_check_editor.setContent('');
                    ger_draft_editor.setContent('');
                    ger_check_editor.setContent('');
                }
            }
            function nav_var(var_number){
                var cbxVariableList = getObj('variable_name');
                var el;
                if (var_number == 0){
                    el = 1;
                } else if (var_number == 'next'){
                    el =  cbxVariableList.selectedIndex + 1;
                    if (el > cbxVariableList.length - 1){
                        el = cbxVariableList.length - 1;
                    }
                } else if (var_number == 'prev'){
                    el =  cbxVariableList.selectedIndex - 1;
                    if (el < 1){
                        el = 1;
                    }
                    
                } else if (var_number == 'last'){
                    el = cbxVariableList.length - 1;
                }
                cbxVariableList.selectedIndex = el;
                load_data('load');
            }
            function check_filter_type(){
                var disabled = getObj('filter_by_varname').checked;
                getObj('filter_l_3').disabled = disabled;
                getObj('filter_l_13').disabled = disabled;
            }
            window.onload = function(){
                fill_comboboxes();
                check_filter_type();
                if (page_list.findById(selected_items.page_list).edit_mode == 2){
                    eng_check_editor.d = 1;
                    eng_check_editor.toggle(0, document.getElementById('eng_check_editorToggleDiv'));
                    ger_check_editor.d = 1;
                    ger_check_editor.toggle(0, document.getElementById('ger_check_editorToggleDiv'));
                    document.getElementById('edit_mode_span').innerHTML = 'Text';
                    document.getElementById('edit_mode_span').style.color = 'red';
                    document.getElementById('edit_mode_span').style.fontWeight = 'bold';
                    document.getElementById('eng_preview_btn').style.display = '';
                    document.getElementById('ger_preview_btn').style.display = '';
                }
                eng_draft_editor.setContent('<?= $data['str_new_english_draft'] ?>');
                eng_check_editor.setContent('<?= $data['str_new_english_checked'] ?>');
                ger_draft_editor.setContent('<?= $data['str_new_german_draft'] ?>');
                ger_check_editor.setContent('<?= $data['str_new_german_checked'] ?>');
            }
            function show_block (blocks){
                var i, block;
                if (typeof blocks == 'object'){
                    for (i = 0; i < blocks.length; i++){
                        block = document.getElementById(blocks[i]);
                        block.style.display == 'none' ? block.style.display = '' : block.style.display = 'none';
                    }
                }
            }
            function open_preview(lng){
                window.open('translation_text_preview.php?var_name='+getObj('variable_name').options[getObj('variable_name').selectedIndex].innerHTML+'&lng='+lng, 'preview', 'scrollbars=yes, resizable=yes');
            }
        </script>
        <form name="frmMain" id="frmMain" method="post" action="" style="padding: 0px 20px 20px 20px;">
            <input type="hidden" name="action" id="action" value="" />
            <table border="0" class="table1">
                <tr>
                    <td colspan="3" style="font-weight: bold; font-size: 17px; text-align: center;">Growmetry Web Page Translation</td>
                </tr>
                <tr id="filter_tr" style="display: none;">
                    <td colspan="2">
                        <div style="" id="filter_by_div">
                            <fieldset style="height: 95px;">
                                <legend style="color: #0A4DBE;">&nbsp;&nbsp;Filter by ...&nbsp;&nbsp;</legend>
                                <table>
                                    <tr>
                                        <td colspan="3">
                                            <input type="text" id="filter_by_text" name="filter_by_text" value="<?= $_REQUEST['filter_by_text'] != "" ? $_REQUEST['filter_by_text'] : "" ?>" />
                                            <span title="Clear Filter" id="clr_flt" style="<?= $_REQUEST['filter_by_text'] == "" ? 'display: none;' : '' ?>" onclick="getObj('filter_by_text').value=''; load_data('load');"> </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label>
                                                <input onclick="check_filter_type();" type="radio" id="filter_by_varname" value="filter_by_varname" name="filter_by_radio" <?= $_REQUEST['filter_by_radio'] == "" || $_REQUEST['filter_by_radio'] == "filter_by_varname" ? 'checked="true"' : "" ?> />
                                                variable
                                            </label>
                                        </td>
                                        <td>
                                            <label>
                                                <input onclick="check_filter_type();" type="radio" id="filter_by_content" value="filter_by_content" name="filter_by_radio" <?= $_REQUEST['filter_by_radio'] == "filter_by_content" ? 'checked="true"' : "" ?> />
                                                content
                                            </label>
                                        </td>
                                        <td style="text-align: right;">
                                            <input type="button" value="Filter"  onclick="load_data('load');" />
                                        </td>
                                    </tr>
                                    <tr style="line-height: 15px;">
                                        <td>
                                            <label>
                                                <input type="radio" id="filter_l_3" value="filter_l_3" name="filter_level" <?= $_REQUEST['filter_level'] == "" || $_REQUEST['filter_level'] == "filter_l_3" ? 'checked="true"' : "" ?> />
                                                Level 3
                                            </label>
                                        </td>
                                        <td>
                                            <label>
                                                <input type="radio" id="filter_l_13" value="filter_l_13" name="filter_level" <?= $_REQUEST['filter_level'] == "filter_l_13" ? 'checked="true"' : "" ?> />
                                                Level 1-3
                                            </label>
                                        </td>
                                        <td style="text-align: right;">
                                            <div id="filtered_levels_div">
                                                <span id="filtered_l_3" style="<?= $filtered_l_3_color ?>">3</span>&nbsp;&nbsp;&nbsp;
                                                <span id="filtered_l_2" style="<?= $filtered_l_2_color ?>">2</span>&nbsp;&nbsp;&nbsp;
                                                <span id="filtered_l_1" style="<?= $filtered_l_1_color ?>">1</span>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </div>
                    </td>
                    <td>
                        <fieldset style="height: 95px; width: 720px; padding: 5px;"><legend style="color: #0A4DBE;">&nbsp;&nbsp;&nbsp;<b>Filter by text assignment</b>&nbsp;&nbsp;&nbsp;</legend>
                            <table border="0" style="">
                                <tr>
                                    <th style="width: 170px;">Text Group</th>
                                    <th style="width: 210px;">Text Type</th>
                                    <th style="width: 170px;">Text Status</th>
                                    <th style="width: 170px;">&nbsp;</th>
                                    <th style="width: 100px;">&nbsp;</th>
                                </tr>
                                <tr>
                                    <td>
                                        <select name="text_group" id="text_group" style="width: 150px;" onchange="">
                                            <option value="-1">(all)</option>
                                        </select>
                                        <div class="gr_ty_st"><?= $group != "" ? $group : "" ?></div>
                                    </td>
                                    <td>
                                        <select name="text_type" id="text_type" style="width: 190px;" onchange="">
                                            <option value="-1">(all)</option>
                                        </select>
                                        <div class="gr_ty_st"><?= $type != "" ? $type : "" ?></div>
                                    </td>
                                    <td>
                                        <select name="text_status" id="text_status" style="width: 100px;" onchange="">
                                            <option value="-1">(all)</option>
                                        </select>
                                        <div class="gr_ty_st"><?= $status_en != "" ? "English: " . $status_en : "" ?></div>
                                    </td>
                                    <td>
                                        <select name="text_status2" id="text_status2" style="width: 100px;" onchange="">
                                            <option value="1">Any</option>
                                            <option value="2">Both</option>
                                            <option value="3">English</option>
                                            <option value="4">German</option>
                                        </select>
                                        <div class="gr_ty_st"><?= $status_ge != "" ? "German: " . $status_ge : "" ?></div>
                                    </td>
                                    <td style="padding-left: 0px;">
                                        <input type="button" value="Filter" onclick="load_data('load');" />
                                        <div class="gr_ty_st" style="padding-left: 0px; padding-top: 5px;"><?= $status_ge != "" ? "(current)" : "" ?></div>
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th style="width: 170px; height: 18px;">Select Page</th>
                    <th style="width: 225px; height: 18px;">Select Text in table</th>
                    <td rowspan="2" style="padding-left: 10px; padding-top: 15px;">
                        <div style="font-size: 10px; font-weight: normal;"><a href="javascript:" onclick="getObj('filter_tr').style.display == 'none'?getObj('filter_tr').style.display = '':getObj('filter_tr').style.display = 'none'">Show/Hide filter</a></div>
                        <div style="font-size: 10px; font-weight: normal;"><a href="javascript:" onclick="getObj('reassignment').style.display == 'none'?getObj('reassignment').style.display = '':getObj('reassignment').style.display = 'none'">Show/Hide re-assignment</a></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <select name="page_name" id="page_name" style="width: 240px;" onchange="fill_variable_list(this.value); load_data('load');">
                            <option value="-1" selected >Please select...</option>
                        </select>

                    </td>
                    <td>
                        <select name="variable_name" id="variable_name" style="width: 220px;" onchange="load_data('load')">
                            <option value="-1">Please select...</option>
                        </select>
                    </td>
                </tr>
            </table>
            <fieldset style="height: 95px; width: 720px; padding: 5px; margin-left: 480px; display: none;" id="reassignment">
                <legend style="color: #0A4DBE;">&nbsp;&nbsp;&nbsp;<b>Re-assignment</b>&nbsp;&nbsp;&nbsp;</legend>
                <table>
                    <tr>
                        <th style="width: 170px; text-align: left;">Text Group</th>
                        <th style="width: 210px; text-align: left;">Text Type</th>
                        <th style="width: 170px; text-align: left;">&nbsp;</th>
                    </tr>
                    <tr>
                        <td style="width: 150px;">
                            <select name="text_group_2" id="text_group_2" <?= $data['str_k_var_number'] ? "" : "disabled" ?> style="width: 150px;" onchange="getObj('reassign').disabled = (this.value == '-1' || getObj('text_type_2').value == '-1')">
                                <option value="-1">Select...</option>
                            </select>
                        </td>
                        <td style="width: 190px;">
                            <select name="text_type_2" id="text_type_2" <?= $data['str_k_var_number'] ? "" : "disabled" ?> style="width: 190px;" onchange="getObj('reassign').disabled = (this.value == '-1' || getObj('text_group_2').value == '-1')">
                                <option value="-1">Select...</option>
                            </select>
                        </td>
                        <td>
                            <input type="button"  disabled id="reassign" name="reassign" value="Re-assign" onclick="load_data('reassign');"/>
                        </td>
                    </tr>
                </table>
            </fieldset>
            <table style="margin-top: 0px; margin-bottom: 0px; width: 1090px;">
                <tr>
                    <td colspan="2">&nbsp;</td>
                    <td style="text-align: center;"><b>Edit Mode:</b> <span id="edit_mode_span" style="font-weight: bold; color: blue;">HTML</span></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td style="text-align: center;">
                        <input id="btnClear2" type="button" value='Clear all fields' onclick="clear_form();" />
                    </td>
                    <td style="width: 50px;">
                        <input id="btnSave2" type="button" value="Save" onclick="load_data('save')" />
                    </td>
                    <td style="width: 370px;">
                        <div id="nav_bar" class="nav_bar">
                            <?
                            $var_count = count($variable_list[$data['lng_fk_page_list']]);
                            $curr_index = 0;
                            if ( $var_count > 0 ) {
                                foreach ( $variable_list[$data['lng_fk_page_list']] as $key => $value ) {
                                    if ( $value['id'] == $data['str_k_var_number'] ) {
                                        $curr_index = $key;
                                    }
                                }
                                echo "<a href='javascript:' onclick='nav_var(0);'>&lt;&lt;&lt;</a>&nbsp;";
                                echo "<a href='javascript:' onclick='nav_var(\"prev\");'>&lt;&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                echo "[&nbsp;&nbsp;" . ($curr_index + 1) . "&nbsp;&nbsp;/&nbsp;&nbsp;" . $var_count . "&nbsp;&nbsp;]";
                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:' onclick='nav_var(\"next\");'>&gt;&gt;</a>";
                                echo "&nbsp;<a href='javascript:' onclick='nav_var(\"last\");'>&gt;&gt;&gt;</a>";
                            }
                            ?>
                        </div>
                    </td>
                    <td style="width: 170px;">
                        <input id="btnSave3" type="button" value="Save" onclick="load_data('save')" />
                    </td>
                </tr>
            </table>

            <table class="table1" border="0" style="margin-top: 40px;">
                <tr>
                    <td>Level 3&nbsp;&nbsp;&nbsp;&nbsp;English NEW <span style="font-size: 80%; font-weight: normal;">"to be checked"</span></td>
                    <td>
                        <a href="javascript:" id="eng_copy_new" style="color: blue; font-size: 80%;" onclick="copy_new(this);">Copy from NEW</a>
                        &nbsp;&nbsp;&nbsp;<input type="button" value="Preview" id="eng_preview_btn" style="font-size: 80%; display: none;" onclick="open_preview('2')" />
                    </td>
                    <td>Level 3&nbsp;&nbsp;&nbsp;&nbsp;German NEW <span style="font-size: 80%; font-weight: normal;">"to be checked"</span></td>
                    <td>
                        <a href="javascript:" id="ger_copy_new" style="color: blue; font-size: 80%;" onclick="copy_new(this);">Copy from NEW</a>
                        &nbsp;&nbsp;&nbsp;<input type="button" value="Preview" id="ger_preview_btn" style="font-size: 80%; display: none;" onclick="open_preview('1')"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-bottom: 20px;">
                        <textarea id="eng_check_editor" name="eng_check_editor" style="height: 200px"></textarea>
                    </td>
                    <td colspan="2">
                        <textarea id="ger_check_editor" name="ger_check_editor" style="height: 200px"></textarea>
                    </td>
                </tr>
                <tr>
                    <td><b>English-Link</b></td>
                    <td><label><input type="radio" name="en_status" id="en_status_checked"  value="4" <?= $data['lng_fk_text_status_en'] == '4' ? 'checked' : '' ?> />Checked</label></td>
                    <td><b>German-Link</b></td>
                    <td><label><input type="radio" name="ge_status" id="ge_status_checked"  <?= $data['lng_fk_text_status_ge'] == '4' ? 'checked' : '' ?> value="4"/>Checked</label></td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-bottom: 10px;"><input name="eng_link" id="eng_link" type="text" style="width: 580px;" value="<?= utf8_encode(stripslashes($data['str_new_english_link'])) ?>" /></td>
                    <td colspan="2"><input name="ger_link"  id="ger_link" type="text" style="width: 580px;" value="<?= utf8_encode(stripslashes($data['str_new_german_link'])) ?>" onchange="modified = true;" /></td>
                </tr>
                <tr>
                    <td colspan="2">Comments</td>
                    <td colspan="2">Comments</td>
                </tr>
                <tr>
                    <td colspan="2" style=""><textarea style="height: 50px;" name="eng_comments" id="eng_comments"><?= utf8_encode(stripslashes($data['str_english_comments'])) ?></textarea></td>
                    <td colspan="2"><textarea style="height: 50px;" name="ger_comments" id="ger_comments" onchange="modified = true;"><?= utf8_encode(stripslashes($data['str_german_comments'])) ?></textarea></td>
                </tr>
                <tr>
                    <td colspan="4" style="padding-top: 10px;">
                        <div style="font-size: 10px; font-weight: normal;"><a href="javascript: void(0);" onclick="show_block(['db_view_header', 'db_view_body']);">Show/Hide Database View</a></div>    
                    </td>
                </tr>
                <tr id="db_view_header" style="display: none;">
                    <td colspan="2">Database View</td>
                    <td colspan="2">Database View</td>
                </tr>
                <tr id="db_view_body" style="display: none;">
                    <td colspan="2"><textarea name="str_new_english_checked" readonly id="str_new_english_checked" style="height: 150px; border: 1px solid #E06060; padding: 3px;" ><?= $data['str_new_english_checked'] ?></textarea></td>
                    <td colspan="2"><textarea name="str_new_german_checked" readonly id="str_new_german_checked" style="height: 150px; border: 1px solid #E06060; padding: 3px;"><?= $data['str_new_german_checked'] ?></textarea></td>
                </tr>
                <tr>
                    <td colspan="4" style="padding-top: 10px;">
                        <div style="font-size: 10px; font-weight: normal;"><a href="javascript: void(0);" onclick="show_block(['draft_header', 'draft_body', 'draft_status']);">Show/Hide Level 2</a></div>    
                    </td>
                </tr>
                <tr id="draft_header" style="display: none;">
                    <td>Level 2&nbsp;&nbsp;&nbsp;&nbsp;English NEW <span style="font-size: 80%; font-weight: normal;">"draft"</span></td>
                    <td><a href="javascript:" id="eng_copy" style="color: blue; font-size: 80%;" onclick="copy_old(this);">Copy from old</a></td>
                    <td>Level 2&nbsp;&nbsp;&nbsp;&nbsp;German NEW <span style="font-size: 80%; font-weight: normal;">"draft"</span></td>
                    <td><a href="javascript:" id="ger_copy" style="color: blue; font-size: 80%;" onclick="copy_old(this);">Copy from old</a></td>
                </tr>
                <tr id="draft_body" style="display: none;">
                    <td colspan="2" style="padding-bottom: 10px;">
                        <textarea id="eng_draft_editor" name="eng_draft_editor" style="height: 200px"></textarea>
                    </td>
                    <td colspan="2">
                        <textarea id="ger_draft_editor" name="ger_draft_editor" style="height: 200px"></textarea>
                    </td>
                </tr>
                <tr id="draft_status" style="display: none;">
                    <td colspan="2">
                        <table width="100%">
                            <tr>
                                <td nowrap style="width: 80px;"><b>Text status:</b></td>
                                <td nowrap style="width: 80px; color: #91361E; "><label><input type="radio" name="en_status" id="en_status_ready" value="1" <?= $data['lng_fk_text_status_en'] == '1' ? 'checked' : '' ?> />Ready</td>
                                <td nowrap style="width: 100px; color: #91361E; "><label><input type="radio" name="en_status" id="en_status_inprogress" value="2" <?= $data['lng_fk_text_status_en'] == '2' ? 'checked' : '' ?> />in Progress</td>
                                <td nowrap style="color: #91361E; "><label><input type="radio" name="en_status" id="en_status_finished"  value="3" onclick="finishing('english')" <?= $data['lng_fk_text_status_en'] == '3' ? 'checked' : '' ?>/>Finished and copy to "to be checked"</td>
                            </tr>
                        </table>
                    </td>
                    <td colspan="2">
                        <table width="100%">
                            <tr>
                                <td nowrap style="width: 80px;"><b>Text status:</b></td>
                                <td nowrap style="width: 80px; color: #91361E; "><label><input type="radio" name="en_status" id="en_status_ready" value="1" <?= $data['lng_fk_text_status_en'] == '1' ? 'checked' : '' ?> />Ready</td>
                                <td nowrap style="width: 100px; color: #91361E; "><label><input type="radio" name="en_status" id="en_status_inprogress" value="2" <?= $data['lng_fk_text_status_en'] == '2' ? 'checked' : '' ?> />in Progress</td>
                                <td nowrap style="color: #91361E; "><label><input type="radio" name="en_status" id="en_status_finished"  value="3" onclick="finishing('english')" <?= $data['lng_fk_text_status_en'] == '3' ? 'checked' : '' ?>/>Finished and copy to "to be checked"</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="padding-top: 10px;">
                        <div style="font-size: 10px; font-weight: normal;"><a href="javascript: void(0);" onclick="show_block(['old_header', 'old_body']);">Show/Hide Level 1</a></div>    
                    </td>
                </tr>
                <tr id="old_header" style="display: none;">
                    <td colspan="2">Level 1&nbsp;&nbsp;&nbsp;&nbsp;English <span style="font-size: 80%; font-weight: normal;">OLD</span><span style="color: #666666; font-weight: normal;"> (Read only!)</span></td>
                    <td colspan="2">Level 1&nbsp;&nbsp;&nbsp;&nbsp;German <span style="font-size: 80%; font-weight: normal;">OLD</span><span style="color: #666666; font-weight: normal;"> (Read only!)</span></td>
                </tr>
                <tr id="old_body" style="display: none;">
                    <td colspan="2"><textarea style="height: 110px;" readonly name="english_old" id="english_old"><?= $data['str_old_english'] ?></textarea></td>
                    <td colspan="2"><textarea style="height: 110px;" readonly name="german_old" id="german_old"><?= $data['str_old_german'] ?></textarea></td>
                </tr>
            </table>
        </form>
        <script type="text/javascript">
            var common_config = {
                id: 'eng_check_editor',
                width: 584,
                height: 200,
                cssclass: 'tinyeditor',
                controlclass: 'tinyeditor-control',
                rowclass: 'tinyeditor-header',
                dividerclass: 'tinyeditor-divider',
                controls: ['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|',
                    'orderedlist', 'unorderedlist', '|',
                    'outdent', 'indent', '|',
                    'image', 'hr', 'link', 'unlink', '|', 'unformat', '|', 'clear_p'/*, 'nbsp'*/],
                footer: true,
                fonts: ['Arial'],
                xhtml: true,
                cssfile: 'tinyeditor/custom.css',
                bodyid: 'editor',
                footerclass: 'tinyeditor-footer',
                toggle: {text: 'source', activetext: 'wysiwyg', cssclass: 'toggle'},
                resize: {cssclass: 'resize'}
            };
            if (page_list.findById(selected_items.page_list).edit_mode == 2){
                common_config.height = 500;
                common_config.toggle = undefined;
                common_config.controls = [];
                common_config.resize = undefined;
            }
            var eng_check_editor = new TINY.editor.edit('eng_check_editor', common_config);
            common_config.id = "ger_check_editor";
            var ger_check_editor = new TINY.editor.edit('ger_check_editor', common_config);
            common_config.height = 200;
            common_config.toggle = {text: 'source', activetext: 'wysiwyg', cssclass: 'toggle'};
            common_config.controls = ['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|',
                'orderedlist', 'unorderedlist', '|',
                'outdent', 'indent', '|',
                'image', 'hr', 'link', 'unlink', '|', 'unformat', '|', 'clear_p'];
            common_config.resize = {cssclass: 'resize'};
            common_config.id = "eng_draft_editor";
            var eng_draft_editor = new TINY.editor.edit('eng_draft_editor', common_config);
            common_config.id = "ger_draft_editor";
            var ger_draft_editor = new TINY.editor.edit('ger_draft_editor', common_config);

        </script>
    </body>
</html>
